package com.ies.dx.dex.file;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.FileInputStream;

import com.ies.dx.util.ByteArrayLittleEdianInput;

public class Main
{
    private static String mDexFileName;
    private static dex_file mDexFile;
    
    public static void main(String[] args)
    {
        if (! parseArgs(args))
            return;
        
        try
        {
            FileInputStream fis = new FileInputStream(mDexFileName);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            byte[] buf = new byte[1024];
            int readed = 0;
            while ((readed = fis.read(buf)) != -1)
            {
                bos.write(buf, 0, readed);
            }
            ByteArrayLittleEdianInput input = new ByteArrayLittleEdianInput(bos.toByteArray());
            
            mDexFile = new dex_file();
            mDexFile.read(input);
            mDexFile.readData(input);
            fis.close();
            mDexFile.show();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        
    }
    
    private static boolean parseArgs(String[] args)
    {
        if (args.length <= 0)
        {
            System.out.println("Please input dex file!");
            return false;
        }
        
        mDexFileName = args[0];
        return true;
    }
}
